package com.tju.ocean_ecology_website.service.impl;

import com.tju.ocean_ecology_website.entity.OrganizationInfo;
import com.tju.ocean_ecology_website.dao.OrganizationInfoDao;
import com.tju.ocean_ecology_website.service.OrganizationInfoService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 组织信息表(OrganizationInfo)表服务实现类
 *
 * @author shaolong
 * @since 2025-04-29 19:33:34
 */
@Service("organizationInfoService")
public class OrganizationInfoServiceImpl implements OrganizationInfoService {
    @Resource
    private OrganizationInfoDao organizationInfoDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public OrganizationInfo queryById(Long id) {
        return this.organizationInfoDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param organizationInfo 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<OrganizationInfo> queryByPage(OrganizationInfo organizationInfo, PageRequest pageRequest) {
        long total = this.organizationInfoDao.count(organizationInfo);
        return new PageImpl<>(this.organizationInfoDao.queryAllByLimit(organizationInfo, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param organizationInfo 实例对象
     * @return 实例对象
     */
    @Override
    public OrganizationInfo insert(OrganizationInfo organizationInfo) {
        this.organizationInfoDao.insert(organizationInfo);
        return organizationInfo;
    }

    /**
     * 修改数据
     *
     * @param organizationInfo 实例对象
     * @return 实例对象
     */
    @Override
    public OrganizationInfo update(OrganizationInfo organizationInfo) {
        this.organizationInfoDao.update(organizationInfo);
        return this.queryById(organizationInfo.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.organizationInfoDao.deleteById(id) > 0;
    }
}
